home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / xbtx.lha / Source / Main.cpp < prev    next >
C/C++ Source or Header  |  1995-12-03  |  15KB  |  536 lines

  1. /*
  2. **    $Id: Main.cpp 1.8 1995/12/03 12:16:23 olsen Exp olsen $
  3. **
  4. **    :ts=4
  5. */
  6.  
  7. /*
  8.  * Copyright © 1995 by Olaf Barthel, All Rights Reserved
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  22.  * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  27.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  28.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * This software has not been validated by the ``Bundesamt fuer Zulassungen in
  31.  * der Telekommunikation'' of the ``Deutsche Bundepost Telekom'' and thus
  32.  * must not be used for accessing the BTX-Network of the Telekom in Germany.
  33.  *
  34.  * Diese Software hat keine Zulassung durch das Bundesamt fuer Zulassungen in
  35.  * der Telekommunikation der Deutschen Bundespost Telekom und darf daher nicht
  36.  * am Netz der Deutschen Bundespost Telekom in Deutschland betrieben werden.
  37.  */
  38.  
  39. /****************************************************************************/
  40.  
  41. #include <dos/dosextens.h>
  42. #include <dos/rdargs.h>
  43.  
  44. #include <clib/dos_protos.h>
  45. #include <clib/exec_protos.h>
  46. #include <clib/utility_protos.h>
  47.  
  48. #ifdef __SASC
  49. #include <pragmas/dos_pragmas.h>
  50. #include <pragmas/exec_pragmas.h>
  51. #include <pragmas/utility_pragmas.h>
  52.  
  53. extern struct ExecBase        *SysBase;
  54. extern struct DosLibrary    *DOSBase;
  55. #endif    // __SASC
  56.  
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #include <stddef.h>
  60. #include <stdio.h>
  61.  
  62. /****************************************************************************/
  63.  
  64. #ifndef _APPLICATION_HPP
  65. #include "Application.hpp"
  66. #endif
  67.  
  68. /****************************************************************************/
  69.  
  70.     // This is where the library bases are kept
  71.  
  72. struct IntuitionBase    *IntuitionBase;
  73. struct GfxBase            *GfxBase;
  74. struct Library            *UtilityBase;
  75. struct Library            *KeymapBase;
  76.  
  77. /****************************************************************************/
  78.  
  79. #ifdef __SASC
  80. char *verstag = "\0$VER: XBTX 1.7 " __AMIGADATE__ "\r\n";
  81. #else
  82. char *verstag = "\0$VER: XBTX 1.7 (3.12.95)\r\n";
  83. #endif    // __SASC
  84.  
  85. #define TEMPLATE    "DEVICE/K,UNIT/K/N,BAUD/K/N,RTSCTS/K,INIT/K,DIAL/K,NUMBER/K,HANGUP/K,FILE/K,SCALEX=XSCALE/K/N,SCALEY=YSCALE/K/N,TEXT/S,SCREEN=PUBSCREEN/K,DIRECT/S,TIMEOUT/K/N"
  86.  
  87. enum    {    ARG_DEVICE,ARG_UNIT,ARG_BAUD,ARG_RTSCTS,ARG_INIT,ARG_DIAL,
  88.             ARG_NUMBER,ARG_HANGUP,ARG_FILE,ARG_SCALEX,ARG_SCALEY,ARG_TEXT,
  89.             ARG_PUBSCREEN,ARG_DIRECT,ARG_TIMEOUT,
  90.             ARGCOUNT
  91.         };
  92.  
  93. /****** XBTX/XBTX ***********************************************************
  94. *
  95. *   NAME
  96. *       XBTX -- BTX/Datex-J decoder (V39)
  97. *
  98. *   SYNOPSIS
  99. *       DEVICE/K,UNIT/K/N,BAUD/K/N,RTSCTS/K,INIT/K,DIAL/K,NUMBER/K,HANGUP/K,
  100. *           FILE/K,SCALEX/K/N,SCALEY/K/N,TEXT/S,SCREEN=PUBSCREEN/K,DIRECT/S,
  101. *           TIMEOUT/K/N
  102. *
  103. *   FUNCTION
  104. *       XBTX is a BTX/Datex-J decoder developed by Arno Augustin and
  105. *       Frank Höring at the University of Erlangen-Nuremberg, Germany.
  106. *       This Amiga version is based upon the original X-Windows
  107. *       implementation, it adds Telesoftware 3-in-4 and FIF format
  108. *       download capabilities, including RLE and LZH decompression.
  109. *       In addition to this, v1.7 supports the 8 bit transparent mode
  110. *       data link and presentation layer options required by KIT.
  111. *       There is still no KIT support in this program, though.
  112. *
  113. *   REQUIREMENTS
  114. *       XBTX requires Amiga operating system v3.0 or higher, an Amiga
  115. *       equipped with at least an MC68020 CPU and if possible video
  116. *       hardware capable of displaying at least 60 distinctly different
  117. *       colours. If XBTX is unable to allocate at least 60 colours for
  118. *       use, it will fall back to a text-only display. Your Amiga better
  119. *       be real fast, as the BTX font conversion routines are dog slow.
  120. *       XBTX must be started from Shell, it does not run from Workbench yet.
  121. *
  122. *   INPUTS
  123. *       DEVICE/K
  124. *           Amiga device driver to use, default is "serial.device".
  125. *
  126. *       UNIT/K/N
  127. *           Amiga device unit number to use, default is 0.
  128. *
  129. *       BAUD/K/N
  130. *           Baud rate to use; if not specified the default baud rate
  131. *           of the device driver will be used.
  132. *
  133. *       RTSCTS/K
  134. *           Turn RTS/CTS handshaking on or off; if not specified the
  135. *           default hardware handshaking mode of the device driver
  136. *           will be used.
  137. *
  138. *       INIT/K
  139. *           Modem initialization command, default is "ATE1V1Q0^M".
  140. *
  141. *       DIAL/K
  142. *           Modem dialing command to use, default is "~~ATD".
  143. *
  144. *       NUMBER/K
  145. *           Phone number to dial in order to connect to the Datex-J
  146. *           service, default is "01910".
  147. *
  148. *       HANGUP/K
  149. *           Modem hang up command to use, default is "~~+++~~ATH0^M".
  150. *
  151. *       FILE/K
  152. *           Name of prerecorded file to playback.
  153. *
  154. *       SCALEX/K/N
  155. *           Factor by which to scale the display in the horizontal
  156. *           direction, must be between 1 and 8; default is 1. This
  157. *           only works with the graphics display.
  158. *
  159. *       SCALEY/K/N
  160. *           Factor by which to scale the display in the vertical
  161. *           direction, must be between 1 and 8; default is 1. This
  162. *           only works with the graphics display.
  163. *
  164. *       TEXT/S
  165. *           Use the text-only display.
  166. *
  167. *       SCREEN=PUBSCREEN/K
  168. *           Open the display on the named public screen.
  169. *
  170. *       DIRECT/S
  171. *           Build screen characters directly on the screen, do not use
  172. *           a temporary offscreen buffer. Will save some memory and may
  173. *           increase on-screen rendering speed, but then maybe not.
  174. *
  175. *       TIMEOUT/K/N
  176. *           Set the modem dial timeout (in seconds), default is 120
  177. *           seconds. You may want to change this value if the dialer
  178. *           responds with a timeout message after the modem has made
  179. *           a connection. Please note that the timeout accounts for
  180. *           the entire login procedure, starting with the modem getting
  181. *           initialized, following the dial command, ending with the
  182. *           modem making the connection and picking up the carrier
  183. *           signal.
  184. *
  185. *   MODEM COMMANDS
  186. *       You can include simple control sequences in the modem commands.
  187. *       The tilde (~) causes a delay of about a second. Prefixing a
  188. *       character with a caret (^) will turn it into a control code,
  189. *       for example ^M gives a carriage return (or Control-M).
  190. *
  191. *   EXAMPLE
  192. *       Dial into the fast modem service with RTS/CTS handshaking
  193. *       enabled:
  194. *           xbtx rtscts=on number=051119304
  195. *
  196. *       Dial into the slow modem service with RTS/CTS handshaking
  197. *       disabled:
  198. *           xbtx rtscts=off
  199. *
  200. *       Open a text-only display on the `term' public screen:
  201. *           xbtx text screen=term
  202. *
  203. *   ENVIRONMENT VARIABLES
  204. *       In place of command line options, you can store your default
  205. *       XBTX options in an environment variable "XBTX.setup". Please
  206. *       note that if you set the variable, XBTX will completly ignore
  207. *       all command line options.
  208. *
  209. *   NOTES
  210. *       This software has not been validated or approved by the
  211. *       "Bundesamt für Zulassungen in der Telekommunikation" of the
  212. *       "Deutsche Bundepost Telekom" and thus must not be used for
  213. *       accessing the BTX-Network of the Telekom in Germany. It is
  214. *       provided solely for educational purposes only.
  215. *
  216. *       This software is provided by the authors "as is" and any
  217. *       express or implied warranties, including, but not limited
  218. *       to, the implied warranties of merchantability and fitness
  219. *       for a particular purpose are disclaimed. In no event shall
  220. *       the authors be liable for any direct, indirect, incidental,
  221. *       special, exemplary, or consequential damages (including,
  222. *       but not limited to, procurement of substitute goods or
  223. *       services; loss of use, data, or profits; or business
  224. *       interruption) however caused and on any theory of
  225. *       liability, whether in contract, strict liability, or tort
  226. *       (including negligence or otherwise) arising in any way out
  227. *       of the use of this software, even if advised of the
  228. *       possibility of such damage.
  229. *
  230. *       You have been warned, kids.
  231. *
  232. *
  233. *       Incidentally, this is my first major attempt at C++
  234. *       programming. Any changes I made to the code are
  235. *       really © Copyright 1995 by Olaf Barthel.
  236. *
  237. *       There is no KIT support in this program. Feel free to add it.
  238. *
  239. *   BUGS
  240. *       The font decoding and output routines are neither blazingly
  241. *       fast, nor shockingly well designed, but they get the job
  242. *       done. Flashing characters are not supported (yet).
  243. *       Concealed characters are always revealed, there is no option
  244. *       to keep them concealed.
  245. *
  246. *       Up to, but not including v1.7, XBTX did not transmit the
  247. *       special key control codes for *, #, etc. correctly. In fact
  248. *       they would get transmitted twice. The data link layer was
  249. *       getting into big trouble if low baud rates were being used.
  250. *
  251. *   AUTHORS
  252. *       Arno Augustin, University of Erlangen-Nuremberg,
  253. *           <aoaugust@cip.informatik.uni-erlangen.de>
  254. *
  255. *       Frank Höring, University of Erlangen-Nuremberg,
  256. *           <fkhoerin@cip.informatik.uni-erlangen.de>
  257. *
  258. *       Olaf Barthel (Amiga port)
  259. *           <olsen@sourcery.han.de>
  260. *
  261. *   SEE ALSO
  262. *       "Functional Specification for BTX-Terminals", DBP Telekom
  263. *       xbtx - a Bildschirmtext-decoder for the X-Window system
  264. *
  265. *****************************************************************************
  266. *
  267. */
  268.  
  269. STATIC struct { STRPTR String; BOOL Value; } BoolTable[] =
  270. {
  271.     "on",    TRUE,
  272.     "true",    TRUE,
  273.     "yes",    TRUE,
  274.     "y",    TRUE,
  275.     "t",    TRUE,
  276.  
  277.     "off",    FALSE,
  278.     "false",FALSE,
  279.     "no",    FALSE,
  280.     "n",    FALSE,
  281.     "f",    FALSE,
  282.  
  283.     NULL
  284. };
  285.  
  286. VOID
  287. CloseLibs(VOID)
  288. {
  289.     if(IntuitionBase)
  290.     {
  291.         CloseLibrary((struct Library *)IntuitionBase);
  292.         IntuitionBase = NULL;
  293.     }
  294.  
  295.     if(GfxBase)
  296.     {
  297.         CloseLibrary((struct Library *)GfxBase);
  298.         GfxBase = NULL;
  299.     }
  300.  
  301.     if(UtilityBase)
  302.     {
  303.         CloseLibrary(UtilityBase);
  304.         UtilityBase = NULL;
  305.     }
  306.  
  307.     if(KeymapBase)
  308.     {
  309.         CloseLibrary(KeymapBase);
  310.         KeymapBase = NULL;
  311.     }
  312. }
  313.  
  314. STRPTR
  315. OpenLibs(VOID)
  316. {
  317.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",37)))
  318.         return("Could not open intuition.library v37");
  319.  
  320.     if(!(GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",39)))
  321.         return("Could not open intuition.library v39");
  322.  
  323.     if(!(UtilityBase = OpenLibrary((UBYTE *)"utility.library",37)))
  324.         return("Could not open utility.library v37");
  325.  
  326.     if(!(KeymapBase = OpenLibrary((UBYTE *)"keymap.library",37)))
  327.         return("Could not open keymap.library v37");
  328.  
  329.     return(NULL);
  330. }
  331.  
  332. int
  333. main(int argc,char **argv)
  334. {
  335.     int Result = RETURN_FAIL;
  336.  
  337.     if(argc)
  338.     {
  339.         STRPTR Grunt;
  340.  
  341.         if(!(Grunt = OpenLibs()))
  342.         {
  343.             struct RDArgs    *Args;
  344.             STRPTR             Array[ARGCOUNT];
  345.             char             VarBuffer[256];
  346.             BOOL             FreeIt;
  347.  
  348.             memset(Array,0,sizeof(Array));
  349.  
  350.             FreeIt = FALSE;
  351.  
  352.             if(GetVar("XBTX.setup",VarBuffer,255,NULL) > 0)
  353.             {
  354.                 if(Args = (struct RDArgs *)AllocDosObject(DOS_RDARGS,NULL))
  355.                 {
  356.                     strcat(VarBuffer,"\n");
  357.  
  358.                     Args->RDA_Source.CS_Buffer     = (UBYTE *)VarBuffer;
  359.                     Args->RDA_Source.CS_Length     = strlen(VarBuffer);
  360.                     Args->RDA_Source.CS_CurChr     = 0;
  361.                     Args->RDA_Flags                |= RDAF_NOPROMPT;
  362.  
  363.                     if(ReadArgs(TEMPLATE,(LONG *)Array,Args))
  364.                         FreeIt = TRUE;
  365.                     else
  366.                     {
  367.                         LONG Error;
  368.  
  369.                         Error = IoErr();
  370.  
  371.                         FreeDosObject(DOS_RDARGS,Args);
  372.                         Args = NULL;
  373.  
  374.                         SetIoErr(Error);
  375.                     }
  376.                 }
  377.             }
  378.             else
  379.                 Args = ReadArgs(TEMPLATE,(LONG *)Array,NULL);
  380.  
  381.             if(Args)
  382.             {
  383.                 Application    App;
  384.                 STRPTR        Device;
  385.                 LONG        Unit;
  386.                 LONG        Baud;
  387.                 BOOL        RTS_CTS;
  388.                 BOOL        TextOnly;
  389.                 BOOL        Direct;
  390.                 STRPTR        Init;
  391.                 STRPTR        Dial;
  392.                 STRPTR        Number;
  393.                 STRPTR        Hangup;
  394.                 STRPTR        File;
  395.                 LONG        ScaleX;
  396.                 LONG        ScaleY;
  397.                 LONG        Timeout;
  398.                 STRPTR        Screen;
  399.                 STRPTR        Error;
  400.  
  401.                 if(Array[ARG_DEVICE])
  402.                     Device = Array[ARG_DEVICE];
  403.                 else
  404.                     Device = "serial.device";
  405.  
  406.                 if(Array[ARG_UNIT])
  407.                     Unit = *(LONG *)Array[ARG_UNIT];
  408.                 else
  409.                     Unit = 0;
  410.  
  411.                 if(Array[ARG_BAUD])
  412.                     Baud = *(LONG *)Array[ARG_BAUD];
  413.                 else
  414.                     Baud = 0;
  415.  
  416.                 if(Array[ARG_RTSCTS])
  417.                 {
  418.                     LONG i;
  419.  
  420.                     RTS_CTS = -1;
  421.  
  422.                     for(i = 0 ; BoolTable[i] . String ; i++)
  423.                     {
  424.                         if(!Stricmp(BoolTable[i] . String,Array[ARG_RTSCTS]))
  425.                         {
  426.                             RTS_CTS = BoolTable[i] . Value;
  427.                             break;
  428.                         }
  429.                     }
  430.                 }
  431.                 else
  432.                     RTS_CTS = -1;
  433.  
  434.                 if(Array[ARG_INIT])
  435.                     Init = Array[ARG_INIT];
  436.                 else
  437.                     Init = "ATE1V1Q0^M";
  438.  
  439.                 if(Array[ARG_DIAL])
  440.                     Dial = Array[ARG_DIAL];
  441.                 else
  442.                     Dial = "~~ATD";
  443.  
  444.                 if(Array[ARG_NUMBER])
  445.                     Number = Array[ARG_NUMBER];
  446.                 else
  447.                     Number = "01910";
  448.  
  449.                 if(Array[ARG_HANGUP])
  450.                     Hangup = Array[ARG_HANGUP];
  451.                 else
  452.                     Hangup = "~~+++~~ATH0^M";
  453.  
  454.                 if(Array[ARG_FILE])
  455.                     File = Array[ARG_FILE];
  456.                 else
  457.                     File = NULL;
  458.  
  459.                 if(Array[ARG_SCALEX])
  460.                     ScaleX = *(LONG *)Array[ARG_SCALEX];
  461.                 else
  462.                     ScaleX = 1;
  463.  
  464.                 if(Array[ARG_SCALEY])
  465.                     ScaleY = *(LONG *)Array[ARG_SCALEY];
  466.                 else
  467.                     ScaleY = 1;
  468.  
  469.                 if(Array[ARG_TEXT])
  470.                     TextOnly = TRUE;
  471.                 else
  472.                     TextOnly = FALSE;
  473.  
  474.                 if(Array[ARG_DIRECT])
  475.                     Direct = TRUE;
  476.                 else
  477.                     Direct = FALSE;
  478.  
  479.                 if(Array[ARG_PUBSCREEN])
  480.                     Screen = Array[ARG_PUBSCREEN];
  481.                 else
  482.                     Screen = NULL;
  483.  
  484.                 if(Array[ARG_TIMEOUT])
  485.                 {
  486.                     Timeout = *(LONG *)Array[ARG_TIMEOUT];
  487.  
  488.                     if(Timeout < 1)
  489.                         Timeout = 1;
  490.                 }
  491.                 else
  492.                     Timeout = 120;
  493.  
  494.                 Error = App.Open(Screen,ScaleX,ScaleY,TextOnly,Direct,File ? File : Device,Unit,Baud,RTS_CTS);
  495.  
  496.                 if(Error)
  497.                     Printf("XBTX: %s\n",Error);
  498.                 else
  499.                 {
  500.                     if(App.AppModem)
  501.                     {
  502.                         if(App.AppModem->Connect(Init,Dial,Number,Hangup,Timeout) == MODEM_Connect)
  503.                             App.DoEvent();
  504.                         else
  505.                             App.WaitForUserInput();
  506.                     }
  507.                     else
  508.                         App.DoEvent();
  509.  
  510.                     App.Close();
  511.                 }
  512.  
  513.                 FreeArgs(Args);
  514.  
  515.                 Result = RETURN_OK;
  516.             }
  517.             else
  518.                 PrintFault(IoErr(),"xBTX");
  519.  
  520.             if(FreeIt)
  521.                 FreeDosObject(DOS_RDARGS,Args);
  522.         }
  523.         else
  524.         {
  525.             extern struct DosLibrary *DOSBase;
  526.  
  527.             if(DOSBase->dl_lib.lib_Version >= 36)
  528.                 Printf("XBTX: %s\n",Grunt);
  529.         }
  530.  
  531.         CloseLibs();
  532.     }
  533.  
  534.     return(Result);
  535. }
  536.